Attribute VB_Name = "par"
Option Explicit

Public PAROpen As Boolean

Public PARAddress(49) As Long
Public PARValue(49) As Long

Public PAREnabled As Boolean
Public Sub PARLoad()

  Dim MyString As String, astring As String, bstring As String

  On Error Resume Next

  Call frmPAR.List1.Clear 'clear
  Call frmPAR.List2.Clear 'clear

  If Not fileexists(App.Path & "\folders\pro action replay\" & ROM_Name$ & ".par") Then Exit Sub 'checks if bookmarks exist

  Open App.Path & "\folders\pro action replay\" & ROM_Name$ & ".par" For Input As #1 'opens file

  While Not EOF(1) 'sorts through entire file
    Input #1, MyString$ 'gets text
    astring$ = Replace(left(MyString$, InStr(MyString$, "|") - 1), "$COMMA$", ",")
    bstring$ = Replace(right(MyString$, Len(MyString$) - InStr(MyString$, "|")), "$COMMA$", ",")
    DoEvents 'cpu shit
    Call frmPAR.List1.AddItem(astring$) 'adds it
    Call frmPAR.List2.AddItem(bstring$) 'adds it
  Wend

  Close #1

End Sub
Public Sub PARRemove()

  If frmPAR.List1.Text <> "" Then Call frmPAR.List1.RemoveItem(frmPAR.List1.ListIndex): Call frmPAR.List2.RemoveItem(frmPAR.List2.ListIndex)
  
  Call PARSave

End Sub

Public Sub PARReset()

  Dim a As Long
  
  For a = LBound(PARAddress) To UBound(PARAddress)
    PARAddress(a) = 0
    PARValue(a) = 0
  Next a
  
  PAREnabled = False
    
End Sub

Public Sub PARSave()

  Dim SaveList As Long

  On Error Resume Next

  If ROM_Name$ = "" Then Exit Sub 'checks to see if a rom is loaded

  If frmPAR.List1.ListCount = 0 And fileexists(App.Path & "\folders\pro action replay\" & ROM_Name$ & ".par") Then 'checks if there's no bookmarks and if the file exists
    Call Kill(App.Path & "\folders\pro action replay\" & ROM_Name$ & ".par") 'deletes file
    Exit Sub
  End If

  If frmPAR.List1.ListCount = 0 Then Exit Sub 'checks if there are any bookmarks

  Open App.Path & "\folders\pro action replay\" & ROM_Name$ & ".par" For Output As #1 'opens the file

  For SaveList& = 0 To frmPAR.List1.ListCount - 1 'sorts through bookmarks
    Print #1, Replace(frmPAR.List1.List(SaveList&), ",", "$COMMA$") & "|" & Replace(frmPAR.List2.List(SaveList&), ",", "$COMMA$") 'saves them
  Next SaveList&

  Close #1

End Sub
Public Sub PARClear()

  Call frmPAR.List1.Clear 'clears list
  Call frmPAR.List2.Clear 'clears list

  Call PARSave 'saves list

End Sub
